package com.kqb.common.exception;

import com.kqb.common.domain.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

/**
 * @author 杉果树皮
 * @date 2025/2/15 9:34
 * @description: 全局异常管理
 */
@ControllerAdvice
public class GlobalException {


    @ResponseBody
    @ExceptionHandler(ValidateException.class)
    public AjaxResult validateException(ValidateException e) {
        return AjaxResult.error("后端验证异常", e.getErrorMap());
    }

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public AjaxResult BusinessException(BusinessException e) {
        return AjaxResult.error("业务异常:" + e.getModule(), e.getDefaultMessage());
    }

    @ResponseBody
    @ExceptionHandler(SQLException.class)
    public AjaxResult SqlException(SQLException e) {
        return AjaxResult.error("数据库异常", e.getMessage());
    }


}
